home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / util / snap_1_4 / part01 next >
Encoding:
Internet Message Format  |  1990-02-11  |  56.0 KB

  1. Path: xanth!cs.odu.edu!Amiga-Request
  2. From: Amiga-Request@cs.odu.edu (Amiga Sources/Binaries Moderator)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v90i067: Snap 1.4 - cut, store, and paste between windows, Part01/04
  5. Message-ID: <11375@xanth.cs.odu.edu>
  6. Date: 11 Feb 90 22:48:57 GMT
  7. Sender: tadguy@cs.odu.edu
  8. Reply-To: micke@slaka.sirius.se (Mikael Karlsson)
  9. Lines: 1871
  10. Approved: tadguy@cs.odu.edu (Tad Guy)
  11. X-Mail-Submissions-To: Amiga@cs.odu.edu
  12. X-Post-Discussions-To: comp.sys.amiga
  13.  
  14. Submitted-by: micke@slaka.sirius.se (Mikael Karlsson)
  15. Posting-number: Volume 90, Issue 067
  16. Archive-name: util/snap-1.4/part01
  17.  
  18. Snap is the perfect tool for the lazy typer. Isn't it irritating when you
  19. look at something on the screen and think: "That is what I'm going to type."?
  20. What if you could just point at it and get the computer to type it for you?
  21. That's where Snap comes to the rescue.  Another thing that irritates me is
  22. that I'm sitting in front of THE computer and still I must have pen and paper
  23. available to scribble down something from the screen that I know I will need
  24. later. Snap provides a solution to that problem also. Just frame it and Snap
  25. creates a window with a copy of the screen contents. Perfect for snapping
  26. text from later on. 
  27.  
  28. Important changes:
  29.  
  30. o You can't use the new Snap to turn off the old version.
  31. o Delays are now specified in milliseconds.
  32. o You can now change parameters without removing and re-installing Snap.
  33. o Use 'snap -Q'/'snap quit' to remove Snap.
  34.  
  35. #!/bin/sh
  36. # This is a shell archive.  Remove anything before this line, then unpack
  37. # it by saving it into a file and typing "sh file".  To overwrite existing
  38. # files, type "sh file -c".  You can also feed this as standard input via
  39. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  40. # will see the following message at the end:
  41. #        "End of archive 1 (of 4)."
  42. # Contents:  .DistFiles README source source/clip.c source/frame.c
  43. #   source/makefile source/minrexx.h source/misc.c source/openclose.c
  44. #   source/patch.c source/rexx.c source/saveilbm.c source/snap.h
  45. #   source/snapasm.s source/snapgfx.c
  46. # Wrapped by tadguy@xanth on Sun Feb 11 17:48:43 1990
  47. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  48. if test -f '.DistFiles' -a "${1}" != "-c" ; then 
  49.   echo shar: Will not clobber existing file \"'.DistFiles'\"
  50. else
  51. echo shar: Extracting \"'.DistFiles'\" \(371 characters\)
  52. sed "s/^X//" >'.DistFiles' <<'END_OF_FILE'
  53. X.DistFiles
  54. XREADME
  55. Xsnap
  56. Xsettings
  57. Xsnap.doc
  58. Xsnap.info
  59. Xstartsnap.rexx
  60. Xsource/clip.c
  61. Xsource/frame.c
  62. Xsource/handler.s
  63. Xsource/ikm.c
  64. Xsource/makefile
  65. Xsource/minrexx.c
  66. Xsource/minrexx.h
  67. Xsource/misc.c
  68. Xsource/openclose.c
  69. Xsource/patch.c
  70. Xsource/rexx.c
  71. Xsource/saveilbm.c
  72. Xsource/settings.c
  73. Xsource/snap.c
  74. Xsource/snap.h
  75. Xsource/snapasm.s
  76. Xsource/snapchars.c
  77. Xsource/snapgfx.c
  78. Xsource/windows.c
  79. END_OF_FILE
  80. if test 371 -ne `wc -c <'.DistFiles'`; then
  81.     echo shar: \"'.DistFiles'\" unpacked with wrong size!
  82. fi
  83. # end of '.DistFiles'
  84. fi
  85. if test -f 'README' -a "${1}" != "-c" ; then 
  86.   echo shar: Will not clobber existing file \"'README'\"
  87. else
  88. echo shar: Extracting \"'README'\" \(244 characters\)
  89. sed "s/^X//" >'README' <<'END_OF_FILE'
  90. XImportant changes:
  91. X
  92. Xo You can't use the new Snap to turn off the old version.
  93. X
  94. Xo Delays are now specified in milliseconds.
  95. X
  96. Xo You can now change parameters without removing and
  97. X  re-installing Snap.
  98. X
  99. Xo Use 'snap -Q'/'snap quit' to remove Snap.
  100. END_OF_FILE
  101. if test 244 -ne `wc -c <'README'`; then
  102.     echo shar: \"'README'\" unpacked with wrong size!
  103. fi
  104. # end of 'README'
  105. fi
  106. if test ! -d 'source' ; then
  107.     echo shar: Creating directory \"'source'\"
  108.     mkdir 'source'
  109. fi
  110. if test -f 'source/clip.c' -a "${1}" != "-c" ; then 
  111.   echo shar: Will not clobber existing file \"'source/clip.c'\"
  112. else
  113. echo shar: Extracting \"'source/clip.c'\" \(2562 characters\)
  114. sed "s/^X//" >'source/clip.c' <<'END_OF_FILE'
  115. X/* This is just plain clipboard handling */
  116. X
  117. XIMPORT struct IOClipReq *ClipReq;
  118. X
  119. XULONG ReadClip(ClipReq, Buf, BufSize, Action)
  120. Xstruct IOClipReq *ClipReq;
  121. XSTRPTR Buf;
  122. XULONG BufSize;
  123. XSHORT Action;
  124. X{
  125. X    ULONG Length;
  126. X    ClipReq->io_Command = CMD_READ;
  127. X    ClipReq->io_Data = Buf;
  128. X    ClipReq->io_Length = BufSize-1L;       /* space for '\0' */
  129. X    if (Action == CLIP_FIRST) {
  130. X        ClipReq->io_Offset = 0L;
  131. X        ClipReq->io_ClipID = 0L;
  132. X    }
  133. X    DoIO(ClipReq);
  134. X    Length = ClipReq->io_Actual;
  135. X    Buf[Length] = '\0';
  136. X    if (Action == CLIP_LAST) {
  137. X        ClipReq->io_Command = CMD_READ;
  138. X        ClipReq->io_Data = NULL;
  139. X        ClipReq->io_Length = 1L;
  140. X        DoIO(ClipReq);                    /* Null read to terminate */
  141. X    }
  142. X    return(Length);
  143. X}
  144. X
  145. XVOID WriteClip(ClipReq, Buf, BufSize, Action)
  146. Xstruct IOClipReq *ClipReq;
  147. XSTRPTR Buf;
  148. XULONG BufSize;
  149. XSHORT Action;
  150. X{
  151. X    if (Action == CLIP_FIRST) {
  152. X        ClipReq->io_Offset = 0L;
  153. X        ClipReq->io_ClipID = 0L;
  154. X    }
  155. X    ClipReq->io_Command = CMD_WRITE;
  156. X    ClipReq->io_Data = Buf;
  157. X    ClipReq->io_Length = BufSize;
  158. X    DoIO(ClipReq);
  159. X    if (Action == CLIP_LAST) {
  160. X        ClipReq->io_Command = CMD_UPDATE;
  161. X        DoIO(ClipReq);
  162. X    }
  163. X}
  164. X
  165. XVOID SaveClip(SnapSpace, SnapSize)
  166. XUBYTE *SnapSpace;
  167. XULONG SnapSize;
  168. X{
  169. X    ULONG Len;
  170. X    WriteClip(ClipReq, "FORM", 4L, CLIP_FIRST);
  171. X    Len = SnapSize+12;
  172. X    WriteClip(ClipReq, (STRPTR)&Len, 4L, CLIP_CONT);
  173. X    WriteClip(ClipReq, "FTXT", 4L, CLIP_CONT);
  174. X    WriteClip(ClipReq, "CHRS", 4L, CLIP_CONT);
  175. X    Len = SnapSize;
  176. X    WriteClip(ClipReq, (STRPTR)&Len, 4L, CLIP_CONT);
  177. X    WriteClip(ClipReq, SnapSpace, Len, CLIP_LAST);
  178. X}
  179. X
  180. Xstruct Snap *FetchClip()
  181. X{
  182. X    struct Snap *Snap = NULL;
  183. X    ULONG temp;
  184. X    ULONG ID[2];
  185. X
  186. X    (VOID)ReadClip(ClipReq, (STRPTR)&ID, 5L, CLIP_FIRST);    /* FORM */
  187. X    if (!strcmp((STRPTR)&ID, "FORM")) {
  188. X        (VOID)ReadClip(ClipReq, (STRPTR)&ID, 5L, CLIP_CONT);     /* size */
  189. X        (VOID)ReadClip(ClipReq, (STRPTR)&ID, 5L, CLIP_CONT);     /* FTXT */
  190. X        if (!strcmp((STRPTR)&ID, "FTXT")) {
  191. X            (VOID)ReadClip(ClipReq, (STRPTR)&ID, 5L, CLIP_CONT);     /* CHRS */
  192. X            if (!strcmp((STRPTR)&ID, "CHRS")) {
  193. X                (VOID)ReadClip(ClipReq, (STRPTR)&ID, 5L, CLIP_CONT); /* #chars */
  194. X                temp = ID[0];
  195. X                Snap = AllocMem((LONG)sizeof(struct Snap)+temp,
  196. X                  MEMF_PUBLIC|MEMF_CLEAR);
  197. X                Snap->Size = sizeof(struct Snap)+temp;
  198. X                ReadClip(ClipReq, &Snap->Chars[0], Snap->Size+1L, CLIP_LAST);
  199. X            }
  200. X        }
  201. X    }
  202. X    return(Snap);
  203. X}
  204. END_OF_FILE
  205. if test 2562 -ne `wc -c <'source/clip.c'`; then
  206.     echo shar: \"'source/clip.c'\" unpacked with wrong size!
  207. fi
  208. # end of 'source/clip.c'
  209. fi
  210. if test -f 'source/frame.c' -a "${1}" != "-c" ; then 
  211.   echo shar: Will not clobber existing file \"'source/frame.c'\"
  212. else
  213. echo shar: Extracting \"'source/frame.c'\" \(1217 characters\)
  214. sed "s/^X//" >'source/frame.c' <<'END_OF_FILE'
  215. XIMPORT struct RastPort rp;
  216. X
  217. XPoint OldFrame[9];
  218. XPoint NewFrame[9];
  219. XLONG OFType = 0;
  220. XUWORD Ptrn;
  221. X
  222. XSTATIC VOID MultiDraw(rp, num, xy)
  223. Xstruct RastPort *rp;
  224. XLONG num;
  225. XPoint *xy;
  226. X{
  227. X    REGISTER LONG i = 0;
  228. X    REGISTER Point *coord = xy;
  229. X    while (i<num) {
  230. X        Move(rp, (LONG)coord->x, (LONG)coord->y);
  231. X        coord++;
  232. X        Draw(rp, (LONG)coord->x, (LONG)coord->y);
  233. X        i++;
  234. X    }
  235. X}
  236. X
  237. XVOID crawl_frame(dir)
  238. XLONG dir;
  239. X{
  240. X    REGISTER UWORD temp = Ptrn;
  241. X    if (dir) {
  242. X        Ptrn = ((Ptrn<<1) & 0xfffe) | ((Ptrn & 0x8000)>>15);
  243. X    } else {
  244. X        Ptrn = ((Ptrn>>1) & 0x7fff) | ((Ptrn & 1)<<15);
  245. X    }
  246. X    temp ^= Ptrn;
  247. X    SetDrPt(&rp, temp);
  248. X    MultiDraw(&rp, OFType, &OldFrame[0]);
  249. X    SetDrPt(&rp, Ptrn);
  250. X}
  251. X
  252. XVOID erase_frame()
  253. X{
  254. X    if (OFType) {
  255. X        MultiDraw(&rp, OFType, &OldFrame[0]);
  256. X        OFType = 0;
  257. X    }
  258. X}
  259. X
  260. XVOID draw_frame(ft)
  261. XLONG ft;
  262. X{
  263. X    REGISTER LONG i;
  264. X      /* Remove old frame */
  265. X    WaitTOF();
  266. X    erase_frame();
  267. X      /* Draw the new frame */
  268. X    SetDrPt(&rp, Ptrn);
  269. X    MultiDraw(&rp, ft, &NewFrame[0]);
  270. X      /* save the frame for erasing later */
  271. X    for (i=0; i<=ft; i++) {
  272. X        OldFrame[i].x = NewFrame[i].x;
  273. X        OldFrame[i].y = NewFrame[i].y;
  274. X    }
  275. X    OFType = ft;
  276. X}
  277. END_OF_FILE
  278. if test 1217 -ne `wc -c <'source/frame.c'`; then
  279.     echo shar: \"'source/frame.c'\" unpacked with wrong size!
  280. fi
  281. # end of 'source/frame.c'
  282. fi
  283. if test -f 'source/makefile' -a "${1}" != "-c" ; then 
  284.   echo shar: Will not clobber existing file \"'source/makefile'\"
  285. else
  286. echo shar: Extracting \"'source/makefile'\" \(1232 characters\)
  287. sed "s/^X//" >'source/makefile' <<'END_OF_FILE'
  288. XOBJS=snap.o openclose.o clip.o patch.o handler.o snapgfx.o \
  289. X snapchars.o frame.o misc.o ikm.o snapasm.o saveilbm.o windows.o \
  290. X rexx.o minrexx.o
  291. XEXE=snap
  292. XSYMS=$(EXE).sym
  293. XSYMSRC=$(EXE).h
  294. XQUICKSYMS=ram:$(SYMS)
  295. X
  296. X# Rexx stuff - Only available with Aztec
  297. XREXXCC=-dSNAPREXX
  298. XREXXOBJS=rexxglue
  299. X
  300. X# Aztec
  301. XCCFLAGS=-q +I$(QUICKSYMS) $(REXXCC)
  302. XASFLAGS=
  303. XLNFLAGS=
  304. XLNOBJS=detach $(REXXOBJS) -lc -la
  305. XSYMFLAGS=+l +h$(SYMS) -o ram:null.o
  306. XCC=cc
  307. XAS=as
  308. XLN=ln
  309. X
  310. X#Lattice
  311. X#CCFLAGS=-v -H$(QUICKSYMS) # -O
  312. X#ASFLAGS=-iLattice:Asm-include/
  313. X#LNFLAGS=NOALVS SC SD ND TO $(EXE) FROM lib:cback.o
  314. X#LNOBJS=LIB lib:lc.lib lib:amiga.lib
  315. X#SYMFLAGS=-ph -o$(SYMS)
  316. X#CC=lc
  317. X#AS=asm
  318. X#LN=blink
  319. X
  320. X.c.o:
  321. X    $(CC) $(CCFLAGS) -o$*.o $*.c
  322. X
  323. X.s.o:
  324. X    $(AS) $(ASFLAGS) $*.s
  325. X
  326. Xall: $(SYMS) $(QUICKSYMS) $(EXE)
  327. X
  328. X# Lattice link
  329. X#$(EXE): $(OBJS) $(EXE).lnk
  330. X#    blink with $(EXE).lnk
  331. X
  332. X#Aztec link
  333. X$(EXE):    $(OBJS)
  334. X    $(LN) $(LNFLAGS) $(OBJS) $(LNOBJS)
  335. X
  336. X$(EXE).lnk:
  337. X    echo >ram:l1 "$(LNFLAGS)"
  338. X    echo >ram:l2 "$(OBJS)"
  339. X    echo >ram:l3 "$(LNOBJS)"
  340. X    join ram:l1 ram:l2 ram:l3 as $(EXE).lnk
  341. X    delete ram:l1 ram:l2 ram:l3
  342. X
  343. X$(SYMS): $(SYMSRC)
  344. X    copy $(SYMSRC) ram:temp.c
  345. X    $(CC) $(SYMFLAGS) ram:temp.c
  346. X    delete ram:temp.c
  347. X
  348. X$(QUICKSYMS): $(SYMS)
  349. X    copy $(SYMS) $(QUICKSYMS)
  350. END_OF_FILE
  351. if test 1232 -ne `wc -c <'source/makefile'`; then
  352.     echo shar: \"'source/makefile'\" unpacked with wrong size!
  353. fi
  354. # end of 'source/makefile'
  355. fi
  356. if test -f 'source/minrexx.h' -a "${1}" != "-c" ; then 
  357.   echo shar: Will not clobber existing file \"'source/minrexx.h'\"
  358. else
  359. echo shar: Extracting \"'source/minrexx.h'\" \(808 characters\)
  360. sed "s/^X//" >'source/minrexx.h' <<'END_OF_FILE'
  361. X/*
  362. X *   Includes for minrexx.c; please refer to that file for
  363. X *   further documentation.
  364. X */
  365. X#include <rexx/rxslib.h>
  366. X/*
  367. X *   This is the list of functions we can access.  (Cheap forward
  368. X *   declarations, too.)
  369. X */
  370. Xlong upRexxPort() ;
  371. Xvoid dnRexxPort() ;
  372. Xvoid dispRexxPort() ;
  373. Xstruct RexxMsg *sendRexxCmd() ;
  374. Xstruct RexxMsg *syncRexxCmd() ;
  375. Xstruct RexxMsg *asyncRexxCmd() ;
  376. Xvoid replyRexxCmd() ;
  377. X/*
  378. X *   Maximum messages that can be pending, and the return codes
  379. X *   for two bad situations.
  380. X */
  381. X#define MAXRXOUTSTANDING (300)
  382. X#define RXERRORIMGONE (100)
  383. X#define RXERRORNOCMD (30)
  384. X/*
  385. X *   This is the association list you build up (statically or
  386. X *   dynamically) that should be terminated with an entry with
  387. X *   NULL for the name . . .
  388. X */
  389. Xstruct rexxCommandList {
  390. X   char *name ;
  391. X   APTR userdata ;
  392. X} ;
  393. END_OF_FILE
  394. if test 808 -ne `wc -c <'source/minrexx.h'`; then
  395.     echo shar: \"'source/minrexx.h'\" unpacked with wrong size!
  396. fi
  397. # end of 'source/minrexx.h'
  398. fi
  399. if test -f 'source/misc.c' -a "${1}" != "-c" ; then 
  400.   echo shar: Will not clobber existing file \"'source/misc.c'\"
  401. else
  402. echo shar: Extracting \"'source/misc.c'\" \(2829 characters\)
  403. sed "s/^X//" >'source/misc.c' <<'END_OF_FILE'
  404. X/* Auto: make
  405. X*/
  406. X
  407. X#define SCREENTOP\
  408. X   (screen->TopEdge << ((screen->ViewPort.Modes & LACE)? 0: 1))
  409. X
  410. XIMPORT struct SnapRsrc *SnapRsrc;
  411. XIMPORT struct IntuitionBase *IntuitionBase;
  412. XIMPORT struct MinList CachedWindows;
  413. X
  414. Xstruct Screen *WhichScreen()
  415. X{
  416. X    REGISTER struct Screen *screen;
  417. X    Forbid();
  418. X    screen = IntuitionBase->FirstScreen;
  419. X    while (screen && IntuitionBase->MouseY < SCREENTOP) {
  420. X        screen = screen->NextScreen;
  421. X    }
  422. X    if (screen == NULL) {     /* Shouldn't happen */
  423. X        screen = IntuitionBase->ActiveScreen;
  424. X    }
  425. X    Permit();
  426. X    return screen;
  427. X}
  428. X
  429. Xstruct Window *WhichWindow(screen)
  430. Xstruct Screen *screen;
  431. X{
  432. X    struct Layer *layer;
  433. X    layer = (struct Layer *)WhichLayer(&screen->LayerInfo,
  434. X      (LONG)screen->MouseX, (LONG)screen->MouseY);
  435. X    if (layer) {
  436. X        return (struct Window *)layer->Window;
  437. X    } else {
  438. X        return NULL;
  439. X    }
  440. X}
  441. X
  442. XVOID FreePlanes(bm, width, height)
  443. Xstruct BitMap *bm;
  444. XLONG width, height;
  445. X{
  446. X    SHORT i;
  447. X    for (i=0; i < bm->Depth; i++) {
  448. X        if (bm->Planes[i]) {
  449. X            FreeRaster(bm->Planes[i], width, height);
  450. X        }
  451. X    }
  452. X}
  453. X
  454. XWORD AllocPlanes(bm, width, height)
  455. Xstruct BitMap *bm;
  456. XLONG width, height;
  457. X{
  458. X    WORD i;
  459. X    for (i=0; i < bm->Depth; i++) {
  460. X        bm->Planes[i] = NULL;
  461. X    }
  462. X    for (i=0; i < bm->Depth; i++) {
  463. X        if (!(bm->Planes[i] = AllocRaster(width, height))) {
  464. X            return 0;
  465. X        }
  466. X        BltClear(bm->Planes[i], RASSIZE(width, height), NULL);
  467. X    }
  468. X    return 1;
  469. X}
  470. X
  471. XVOID CacheWindow(Win, xoff, yoff, fw, fh)
  472. Xstruct Window *Win;
  473. XLONG xoff;
  474. XLONG yoff;
  475. XSHORT fw;
  476. XSHORT fh;
  477. X{
  478. X    struct CacheWindow *cw;
  479. X    if (!(cw = AllocMem((LONG)sizeof(struct CacheWindow),
  480. X      MEMF_PUBLIC|MEMF_CLEAR))) {
  481. X        return;
  482. X    }
  483. X    cw->Window = Win;
  484. X    cw->xoff = xoff;
  485. X    cw->yoff = yoff;
  486. X    cw->fw = fw;
  487. X    cw->fh = fh;
  488. X    AddHead((struct List *)&CachedWindows, (struct Node *)cw);
  489. X    if (SnapRsrc->CacheSize > 0) {
  490. X        --SnapRsrc->CacheSize;
  491. X    } else {
  492. X        FreeMem(RemTail((struct List *)&CachedWindows),
  493. X          (LONG)sizeof(struct CacheWindow));
  494. X    }
  495. X}
  496. X
  497. Xstruct CacheWindow *GetCachedWindow(Screen, Win)
  498. Xstruct Screen *Screen;
  499. Xstruct Window *Win;
  500. X{
  501. X    struct CacheWindow *cw = (struct CacheWindow *)CachedWindows.mlh_Head;
  502. X
  503. X    while (cw->Node.mln_Succ) {
  504. X        if (cw->Window == Win) {
  505. X            LONG LockVal = LockIBase(0L);
  506. X            REGISTER struct Window *w = Screen->FirstWindow;
  507. X            while (w && w != Win) {
  508. X                w = w->NextWindow;
  509. X            }
  510. X            UnlockIBase(LockVal);
  511. X            if (!w) {
  512. X                return NULL;
  513. X            }
  514. X            Remove((struct Node *)cw);
  515. X            AddHead((struct List *)&CachedWindows, (struct Node *)cw);
  516. X            return cw;
  517. X        }
  518. X        cw = (struct CacheWindow *)cw->Node.mln_Succ;
  519. X    }
  520. X    return NULL;
  521. X}
  522. END_OF_FILE
  523. if test 2829 -ne `wc -c <'source/misc.c'`; then
  524.     echo shar: \"'source/misc.c'\" unpacked with wrong size!
  525. fi
  526. # end of 'source/misc.c'
  527. fi
  528. if test -f 'source/openclose.c' -a "${1}" != "-c" ; then 
  529.   echo shar: Will not clobber existing file \"'source/openclose.c'\"
  530. else
  531. echo shar: Extracting \"'source/openclose.c'\" \(7742 characters\)
  532. sed "s/^X//" >'source/openclose.c' <<'END_OF_FILE'
  533. X/* Auto: make
  534. X*/
  535. X
  536. XIMPORT LONGBITS startsignal, insertsignal, cancelsignal, donesignal;
  537. XIMPORT LONGBITS movesignal, clicksignal, timersignal, initsignal, cwsignal;
  538. XIMPORT ULONG startsignum, insertsignum, cancelsignum, donesignum;
  539. XIMPORT ULONG movesignum, clicksignum, timersignum, initsignum, cwsignum;
  540. X
  541. X/* program */
  542. XIMPORT struct SnapRsrc *SnapRsrc;
  543. XIMPORT struct Task *MyTask;
  544. X
  545. X/* Snap state machine */
  546. XIMPORT WORD action;
  547. XIMPORT WORD state;
  548. X
  549. X/* clipboard */
  550. XIMPORT struct IOClipReq *ClipReq;
  551. XIMPORT struct MsgPort *ClipPort;
  552. X
  553. X/* timer device */
  554. XIMPORT struct MsgPort *TimerPort;
  555. XIMPORT struct timerequest MyTR;
  556. X
  557. X/* input device */
  558. XIMPORT struct MsgPort *inputDevPort;
  559. XIMPORT struct Interrupt handlerStuff;
  560. XIMPORT struct IOStdReq *inputRequestBlock;
  561. X
  562. XIMPORT UBYTE *CharData;
  563. X
  564. X/* console */
  565. XIMPORT struct MsgPort *ConPort;
  566. XIMPORT struct IOStdReq *ConIOR;
  567. XIMPORT struct KeyMap keymap;
  568. X
  569. X/* windows */
  570. XIMPORT struct MsgPort *Sharedport;
  571. XIMPORT SHORT Sharedrefs;
  572. XIMPORT struct MinList CachedWindows;
  573. X
  574. X/* libraries */
  575. XIMPORT struct IntuitionBase *IntuitionBase;
  576. XIMPORT struct GfxBase       *GfxBase;
  577. XIMPORT struct LayersBase    *LayersBase;
  578. XIMPORT struct ArpBase       *ArpBase;
  579. X
  580. X/* graphics */
  581. XIMPORT struct RastPort TempRp;
  582. XIMPORT struct BitMap TempBM;
  583. XIMPORT UBYTE *TempRaster;
  584. X
  585. XIMPORT struct Image DiskImage;
  586. XUWORD ImData[24] = {
  587. X    /* BitPlane 0 */
  588. X    0xFFFF,
  589. X    0xF00F,
  590. X    0xF7EF,
  591. X    0xF42F,
  592. X    0xF7EF,
  593. X    0xF00F,
  594. X    0xF3CF,
  595. X    0xF2CF,
  596. X    0xF2CF,
  597. X    0xFFFF,
  598. X    0xFFFF,
  599. X    0xFFFF,
  600. X    0xFFFF,
  601. X    0xFFFF,
  602. X    0xFFFF,
  603. X    0xFFFF,
  604. X    0xFFFF,
  605. X    0xFFFF,
  606. X    0xFFFF,
  607. X    0xFFFF,
  608. X    0xFFFF,
  609. X    0xFFFF,
  610. X    0xFFFF,
  611. X    0xFFFF
  612. X};
  613. X
  614. XVOID CloseStuff()
  615. X{
  616. X    SafeRestore();
  617. X    {
  618. X        struct CacheWindow *cw;
  619. X        while (cw = (struct CacheWindow *)
  620. X          RemHead((struct List *)&CachedWindows)) {
  621. X            FreeMem(cw, (LONG)sizeof(struct CacheWindow));
  622. X        }
  623. X    }
  624. X    if (DiskImage.ImageData) FreeMem(DiskImage.ImageData, 32L);
  625. X    if (TempRaster)         FreeRaster(TempRaster, 16L, 16L);
  626. X    if (CharData)           FreeMem(CharData, 256L*32);
  627. X    if (inputRequestBlock) {
  628. X        if (inputRequestBlock->io_Device) {
  629. X            inputRequestBlock->io_Command = IND_REMHANDLER;  /* Remove handler */
  630. X            inputRequestBlock->io_Data    = (APTR)&handlerStuff;
  631. X            DoIO(inputRequestBlock);
  632. X            CloseDevice(inputRequestBlock);
  633. X        }
  634. X        DeleteExtIO(inputRequestBlock);
  635. X    }
  636. X    if (inputDevPort)       DeletePort(inputDevPort);
  637. X    if (TimerPort) {
  638. X        DeletePort(TimerPort);
  639. X        CloseDevice((struct IOStdReq *)&MyTR);
  640. X    }
  641. X    if (ConIOR) {
  642. X        CloseDevice(ConIOR);
  643. X        DeleteExtIO(ConIOR);
  644. X    }
  645. X    if (ConPort)            DeletePort(ConPort);
  646. X    if (ClipReq) {
  647. X        if (ClipReq->io_Device) {
  648. X            CloseDevice(ClipReq);
  649. X        }
  650. X        DeleteExtIO(ClipReq);
  651. X    }
  652. X    if (ClipPort)           DeletePort(ClipPort);
  653. X    if (startsignum != -1)  FreeSignal(startsignum);
  654. X    if (donesignum != -1)   FreeSignal(donesignum);
  655. X    if (cancelsignum != -1) FreeSignal(cancelsignum);
  656. X    if (movesignum != -1)   FreeSignal(movesignum);
  657. X    if (insertsignum != -1) FreeSignal(insertsignum);
  658. X    if (clicksignum != -1)  FreeSignal(clicksignum);
  659. X    if (timersignum != -1)  FreeSignal(timersignum);
  660. X    if (initsignum != -1)   FreeSignal(initsignum);
  661. X    if (cwsignum != -1)     FreeSignal(cwsignum);
  662. X    if (SnapRsrc) {
  663. X        RemResource(SnapRsrc);
  664. X        Kill(SnapRsrc);
  665. X    }
  666. X    if (ArpBase)            CloseLibrary((struct Library *)ArpBase);
  667. X    if (IntuitionBase)      CloseLibrary((struct Library *)IntuitionBase);
  668. X    if (GfxBase)            CloseLibrary((struct Library *)GfxBase);
  669. X    if (LayersBase)         CloseLibrary((struct Library *)LayersBase);
  670. X}
  671. X
  672. XWORD OpenStuff()
  673. X{
  674. X    action = noaction;
  675. X    state  = waiting;
  676. X    inputRequestBlock = NULL;
  677. X
  678. X    Sharedrefs = 0;
  679. X    Sharedport = NULL;
  680. X    NewList((struct NewList *)&CachedWindows);
  681. X
  682. X    /* Set up everything we need. */
  683. X
  684. X    /* libraries */
  685. X
  686. X    if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0L)))
  687. X        return 0;
  688. X    if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 0L)))
  689. X        return 0;
  690. X    if (!(LayersBase = (struct LayersBase *)OpenLibrary("layers.library", 0L)))
  691. X        return 0;
  692. X    ArpBase = (struct ArpBase *)OpenLibrary(ArpName, ArpVersion);
  693. X
  694. X    /* signals */
  695. X
  696. X    if ((startsignum = AllocSignal(-1L)) == -1L)
  697. X        return 0;
  698. X    if ((insertsignum = AllocSignal(-1L)) == -1L)
  699. X        return 0;
  700. X    if ((cancelsignum = AllocSignal(-1L)) == -1L)
  701. X        return 0;
  702. X    if ((donesignum = AllocSignal(-1L)) == -1L)
  703. X        return 0;
  704. X    if ((movesignum = AllocSignal(-1L)) == -1L)
  705. X        return 0;
  706. X    if ((clicksignum = AllocSignal(-1L)) == -1L)
  707. X        return 0;
  708. X    if ((timersignum = AllocSignal(-1L)) == -1L)
  709. X        return 0;
  710. X    if ((initsignum = AllocSignal(-1L)) == -1L)
  711. X        return 0;
  712. X    if ((cwsignum = AllocSignal(-1L)) == -1L)
  713. X        return 0;
  714. X    MyTask = FindTask(NULL);                  /* Find myself to Signal me.  */
  715. X    startsignal  = 1L << startsignum;         /* No good to use bit numbers */
  716. X    insertsignal = 1L << insertsignum;
  717. X    cancelsignal = 1L << cancelsignum;
  718. X    donesignal   = 1L << donesignum;
  719. X    movesignal   = 1L << movesignum;
  720. X    clicksignal  = 1L << clicksignum;
  721. X    timersignal  = 1L << timersignum;
  722. X    initsignal   = 1L << initsignum;
  723. X    cwsignal     = 1L << cwsignum;
  724. X
  725. X    /* clipboard device */
  726. X
  727. X    if (!(ClipPort = CreatePort(0L, 0L)))
  728. X        return 0;
  729. X    if (!(ClipReq = (struct IOClipReq *)CreateExtIO(ClipPort, (LONG)sizeof(*ClipReq))))
  730. X        return 0;
  731. X    if (OpenDevice("clipboard.device", 0L, ClipReq, 0L))
  732. X        return 0;
  733. X    ClipReq->io_ClipID = 0L;
  734. X
  735. X    /* console device */
  736. X
  737. X    if (!(ConPort = CreatePort(0L, 0L)))
  738. X        return 0;
  739. X    if (!(ConIOR = (struct IOStdReq *)CreateExtIO(ConPort, (LONG)sizeof(struct IOStdReq))))
  740. X        return 0;
  741. X    if (OpenDevice("console.device", -1L, ConIOR, 0L))
  742. X        return 0;
  743. X
  744. X    /* timer device */
  745. X    if (!(TimerPort = CreatePort(NULL, 0L)))
  746. X        return 0;
  747. X    if (OpenDevice(TIMERNAME, UNIT_MICROHZ, (struct IOStdReq *)&MyTR, 0L))
  748. X        return 0;
  749. X    MyTR.tr_node.io_Message.mn_ReplyPort = TimerPort;
  750. X    MyTR.tr_node.io_Command = TR_ADDREQUEST;
  751. X
  752. X    /* input devive */
  753. X
  754. X    if (!(inputDevPort = CreatePort(0L, 0L)))
  755. X        return 0;
  756. X    if (!(inputRequestBlock = (struct IOStdReq *)CreateExtIO(inputDevPort, (LONG)sizeof(struct IOStdReq))))
  757. X        return 0;
  758. X    if (OpenDevice("input.device", 0L, inputRequestBlock, 0L))
  759. X        return 0;
  760. X
  761. X    /* input handler */
  762. X
  763. X    handlerStuff.is_Data = (APTR)0x534E4150; /* Set up for installation of */
  764. X    handlerStuff.is_Code = myhandler;        /* myhandler.                 */
  765. X    handlerStuff.is_Node.ln_Pri = SnapRsrc->Priority;
  766. X                                             /* Ahead of intuition, please */
  767. X    handlerStuff.is_Node.ln_Name = "Snap Input Handler";
  768. X
  769. X    inputRequestBlock->io_Command = IND_ADDHANDLER;
  770. X    inputRequestBlock->io_Data    = (APTR)&handlerStuff;
  771. X
  772. X    DoIO(inputRequestBlock);  /* Add me. */
  773. X
  774. X
  775. X    /* Aligned font bitmap to use when matching */
  776. X
  777. X    if (!(CharData = AllocRaster(16L, 256L*16))) {
  778. X        return 0;
  779. X    }
  780. X
  781. X    /* temporary raster */
  782. X
  783. X    if (!(TempRaster = AllocRaster(16L, 16L)))
  784. X        return 0;
  785. X    InitRastPort(&TempRp);                   /* Init RastPort used for */
  786. X    InitBitMap(&TempBM, 1L, 16L, 16L);       /* Locating position of   */
  787. X    TempBM.Planes[0] = TempRaster;           /* first character.       */
  788. X    TempRp.BitMap = &TempBM;
  789. X
  790. X    if (!(DiskImage.ImageData = AllocMem(48L, MEMF_CHIP))) {
  791. X        return 0;
  792. X    }
  793. X    CopyMem((char *)&ImData[0], (char *)DiskImage.ImageData, 48L);
  794. X    return 1;
  795. X}
  796. END_OF_FILE
  797. if test 7742 -ne `wc -c <'source/openclose.c'`; then
  798.     echo shar: \"'source/openclose.c'\" unpacked with wrong size!
  799. fi
  800. # end of 'source/openclose.c'
  801. fi
  802. if test -f 'source/patch.c' -a "${1}" != "-c" ; then 
  803.   echo shar: Will not clobber existing file \"'source/patch.c'\"
  804. else
  805. echo shar: Extracting \"'source/patch.c'\" \(1837 characters\)
  806. sed "s/^X//" >'source/patch.c' <<'END_OF_FILE'
  807. X/* This patch is a quite ugly way to solve the problem
  808. X** that occurs when Intuition tries to draw something
  809. X** in a screen which has it's layers locked.
  810. X** The problem is solved by disabling dangerous functions.
  811. X** Some functions remain because they require more work.
  812. X** An example of this is OpenWindow(), since OpenWindow()
  813. X** can't be as easily ignored as the functions that ARE
  814. X** patched here. OpenWindow() would require some sort of
  815. X** semaphore locking and waiting - and so we're back where
  816. X** we started.
  817. X*/
  818. X
  819. Xtypedef VOID (*FPTR)();
  820. X
  821. XIMPORT struct IntuitionBase *IntuitionBase;
  822. X#define LVOWindowToBack   -0x0132L
  823. X#define LVOWindowToFront  -0x0138L
  824. X#define LVOActivateWindow -0x01c2L
  825. X
  826. XVOID myActivateWindow(), myWindowToFront(), myWindowToBack();
  827. X
  828. XLONG oldActivateWindow, oldWindowToFront, oldWindowToBack;
  829. X
  830. XSTATIC WORD patched = 0;
  831. X
  832. XVOID SafePatch()
  833. X{
  834. X    if (!patched) {
  835. X        Forbid();     /* I don't expect interrupts to do much intuition */
  836. X        oldActivateWindow = (LONG)SetFunction((struct Library *)IntuitionBase,
  837. X          LVOActivateWindow, (FPTR)myActivateWindow);
  838. X        oldWindowToFront = (LONG)SetFunction((struct Library *)IntuitionBase,
  839. X          LVOWindowToFront, (FPTR)myWindowToFront);
  840. X        oldWindowToBack =  (LONG)SetFunction((struct Library *)IntuitionBase,
  841. X          LVOWindowToBack, (FPTR)myWindowToBack);
  842. X        Permit();
  843. X        patched = 1;
  844. X    }
  845. X}
  846. X
  847. XVOID SafeRestore()
  848. X{
  849. X    if (patched) {
  850. X        Forbid();
  851. X        (VOID)SetFunction((struct Library *)IntuitionBase,
  852. X          LVOActivateWindow, (FPTR)oldActivateWindow);
  853. X        (VOID)SetFunction((struct Library *)IntuitionBase,
  854. X          LVOWindowToFront, (FPTR)oldWindowToFront);
  855. X        (VOID)SetFunction((struct Library *)IntuitionBase,
  856. X          LVOWindowToBack, (FPTR)oldWindowToBack);
  857. X        Permit();
  858. X        patched = 0;
  859. X    }
  860. X}
  861. END_OF_FILE
  862. if test 1837 -ne `wc -c <'source/patch.c'`; then
  863.     echo shar: \"'source/patch.c'\" unpacked with wrong size!
  864. fi
  865. # end of 'source/patch.c'
  866. fi
  867. if test -f 'source/rexx.c' -a "${1}" != "-c" ; then 
  868.   echo shar: Will not clobber existing file \"'source/rexx.c'\"
  869. else
  870. echo shar: Extracting \"'source/rexx.c'\" \(847 characters\)
  871. sed "s/^X//" >'source/rexx.c' <<'END_OF_FILE'
  872. X/* Auto: make
  873. X*/
  874. X
  875. X#ifdef SNAPREXX
  876. X#include "minrexx.h"
  877. X
  878. XIMPORT struct SnapRsrc *SnapRsrc;
  879. X
  880. XVOID rexxprepend(), rexxappend();
  881. Xint disp();
  882. X
  883. Xstruct rexxCommandList rcl[] = {
  884. X    { "prepend", (APTR)&rexxprepend },
  885. X    { "append", (APTR)&rexxappend },
  886. X    { NULL, NULL }
  887. X};
  888. X
  889. Xchar result[17];
  890. X
  891. Xint disp(msg, dat, p)
  892. Xregister struct RexxMsg *msg ;
  893. Xregister struct rexxCommandList *dat ;
  894. Xchar *p ;
  895. X{
  896. X    result[0] = '\0';
  897. X    ((int (*)())(dat->userdata))(msg, p) ;
  898. X    replyRexxCmd(msg, 0L, 0L, &result[0]);
  899. X    return 1;
  900. X}
  901. X
  902. XVOID pend(addr, p)
  903. Xchar *addr;
  904. Xchar *p;
  905. X{
  906. X    strcpy(&result[0], addr);
  907. X    if (*p) {
  908. X        strncpy(addr, p + 1, 16);
  909. X    }
  910. X}
  911. X
  912. XVOID rexxprepend(msg, p)
  913. Xstruct RexxMsg *msg ;
  914. Xchar *p ;
  915. X{
  916. X    pend(&SnapRsrc->Prepend[0], p);
  917. X}
  918. X
  919. XVOID rexxappend(msg, p)
  920. Xstruct RexxMsg *msg ;
  921. Xchar *p ;
  922. X{
  923. X    pend(&SnapRsrc->Append[0], p);
  924. X}
  925. X
  926. X#endif
  927. END_OF_FILE
  928. if test 847 -ne `wc -c <'source/rexx.c'`; then
  929.     echo shar: \"'source/rexx.c'\" unpacked with wrong size!
  930. fi
  931. # end of 'source/rexx.c'
  932. fi
  933. if test -f 'source/saveilbm.c' -a "${1}" != "-c" ; then 
  934.   echo shar: Will not clobber existing file \"'source/saveilbm.c'\"
  935. else
  936. echo shar: Extracting \"'source/saveilbm.c'\" \(5748 characters\)
  937. sed "s/^X//" >'source/saveilbm.c' <<'END_OF_FILE'
  938. X/* Auto: make
  939. X*/
  940. X
  941. XIMPORT BPTR SnapFile;
  942. XIMPORT BYTE TranspBuf[];
  943. X
  944. X#define ID(a,b,c,d) ((a << 24L) | (b << 16L) | (c << 8L) | (d))
  945. X
  946. Xstruct ckHdr {
  947. X    LONG ChunkName;
  948. X    LONG ChunkSize;
  949. X};
  950. X
  951. Xstruct BitMapHeader
  952. X{
  953. X   UWORD w,h;
  954. X   WORD  x,y;
  955. X   UBYTE nPlanes;
  956. X   UBYTE masking;
  957. X   UBYTE compression;
  958. X   UBYTE pad1;
  959. X   UWORD transparentColor;
  960. X   UBYTE xAspect, yAspect;
  961. X   WORD  pageWidth, pageHeight;
  962. X};
  963. X
  964. Xstruct ckHdr FORM = {
  965. X    ID('F','O','R','M'),
  966. X    0L
  967. X};
  968. XLONG TYPE = ID('I','L','B','M');
  969. X
  970. Xstruct ckHdr BMHD = {
  971. X    ID('B','M','H','D'),
  972. X    sizeof(struct BitMapHeader)
  973. X};
  974. Xstruct BitMapHeader BMHdr = {
  975. X   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  976. X};
  977. X
  978. Xstruct ckHdr CAMG = {
  979. X    ID('C','A','M','G'),
  980. X    4L
  981. X};
  982. XULONG ViewMode = NULL;
  983. X
  984. Xstruct ckHdr CMAP = {
  985. X    ID('C','M','A','P'),
  986. X    0L
  987. X};
  988. X
  989. Xstruct ckHdr BODY = {
  990. X    ID('B','O','D','Y'),
  991. X    0L
  992. X};
  993. X
  994. XUBYTE *buf;
  995. XWORD bufcnt;
  996. XULONG totalsize;
  997. X
  998. XWORD bumpmode;
  999. X#define BUMP_CALC   1
  1000. X#define BUMP_SAVE   2
  1001. X
  1002. XWORD bump(cnt, dataptr, size)
  1003. XWORD cnt;
  1004. XUBYTE *dataptr;
  1005. XWORD size;
  1006. X{
  1007. X    REGISTER LONG tsize = size;
  1008. X    if (tsize) {
  1009. X        totalsize += tsize + 1;     /* Don't forget the count-byte */
  1010. X    }
  1011. X    if (bumpmode == BUMP_CALC) {    /* Just calculating? */
  1012. X        return 1;                   /* Don't do the save */
  1013. X    }
  1014. X    if (bufcnt + tsize + 1 >= 4096 || tsize == 0) {
  1015. X        if (Write(SnapFile, buf, (LONG)bufcnt) == -1L) {
  1016. X            return 0;
  1017. X        }
  1018. X        bufcnt = 0;
  1019. X    }
  1020. X    buf[bufcnt++] = cnt;
  1021. X    CopyMem((char *)dataptr, (char *)&buf[bufcnt], tsize);
  1022. X    bufcnt += tsize;
  1023. X    return 1;
  1024. X}
  1025. X
  1026. XULONG WriteBody(BM)
  1027. Xstruct BitMap *BM;
  1028. X{
  1029. X    WORD scanline, plane;
  1030. X    REGISTER WORD bpr = BM->BytesPerRow;
  1031. X    REGISTER WORD i, j;
  1032. X    LONG offset = 0L;
  1033. X    REGISTER UBYTE data;
  1034. X    REGISTER UBYTE *bd;
  1035. X
  1036. X    totalsize = 0L;
  1037. X
  1038. X    if (!(buf = AllocMem(4096L, MEMF_PUBLIC))) {
  1039. X        return NULL;
  1040. X    }
  1041. X
  1042. X    bufcnt = 0;
  1043. X    for (scanline = 0; scanline < BM->Rows; ++scanline) {
  1044. X        for (plane = 0; plane < BM->Depth; ++plane) {
  1045. X            bd = BM->Planes[plane]+offset;
  1046. X            i = 1;
  1047. X            j = bpr - 1;
  1048. X            data = bd[0];
  1049. X            while (j) {
  1050. X                if (bd[i] == data) {        /* Equal bytes? */
  1051. X                    --i;                    /* First equal byte */
  1052. X                    if (i > 0) {            /* Old "random" data to save */
  1053. X                        if (!bump((WORD)(i - 1), bd, i)) {
  1054. X                            return NULL;
  1055. X                        }
  1056. X                    }
  1057. X                    bd = &bd[i];        /* Start of equal bytes */
  1058. X                    i = 2;              /* 0 & 1 is equal       */
  1059. X                    --j;
  1060. X                    while (i < 128 && j && bd[i] == data) {
  1061. X                        ++i;
  1062. X                        --j;
  1063. X                    }
  1064. X                    if (!bump((WORD)-(i - 1), &bd[i - 1], 1)) {
  1065. X                        return NULL;
  1066. X                    }
  1067. X                    goto new_block;
  1068. X                } else {                    /* Not equal. Check block range */
  1069. X                    if (i == 128) {         /* Block limit                  */
  1070. X                        if (!bump((WORD)(i - 1), bd, i)) {
  1071. X                            return NULL;
  1072. X                        }
  1073. Xnew_block:
  1074. X                        bd = &bd[i];  /* Start new block              */
  1075. X                        i = 0;
  1076. X                        if (j == 0) {
  1077. X                            break;
  1078. X                        }
  1079. X                    }
  1080. X                }
  1081. X                  /* Different byte or a new start */
  1082. X                data = bd[i];               /* New possible equal       */
  1083. Xnext_byte:
  1084. X                ++i;
  1085. X                --j;
  1086. X            }
  1087. X            if (i != 0) {                   /* Data to save */
  1088. X                if (!bump((WORD)(i - 1), bd, i)) {
  1089. X                    return NULL;
  1090. X                }
  1091. X            }
  1092. X        }
  1093. X        offset += BM->BytesPerRow;
  1094. X    }
  1095. X    if (!bump(0, NULL, 0)) {   /* Flush any bytes left if the buffer */
  1096. X        return NULL;
  1097. X    }
  1098. X    FreeMem(buf, 4096L);
  1099. X    return totalsize;
  1100. X}
  1101. X
  1102. XWORD SaveGS(GS)
  1103. Xstruct GfxSnap *GS;
  1104. X{
  1105. X    ULONG BODYPos;
  1106. X    UBYTE *oldtitle;
  1107. X
  1108. X    oldtitle = GS->window->Title;
  1109. X    SetWindowTitles(GS->window, "Saving...", NULL);
  1110. X
  1111. X    bumpmode = BUMP_SAVE;
  1112. X
  1113. X    BMHdr.w = GS->BM.BytesPerRow * 8;
  1114. X    BMHdr.h = GS->height;
  1115. X    BMHdr.x = BMHdr.y = 0;
  1116. X    BMHdr.nPlanes = GS->depth;
  1117. X    BMHdr.masking = 0;
  1118. X    BMHdr.compression = 1;
  1119. X    BMHdr.transparentColor = dectoint(TranspBuf);
  1120. X    BMHdr.xAspect = BMHdr.xAspect = 1;
  1121. X    BMHdr.pageWidth = GS->pagew;
  1122. X    BMHdr.pageHeight = GS->pageh;
  1123. X    ViewMode = GS->viewmode;
  1124. X
  1125. X    CMAP.ChunkSize = (LONG)3 * (GS->viewmode & HAM ? 16 : 1L << GS->depth);
  1126. X
  1127. X    if (Write(SnapFile, (char *)&FORM,
  1128. X      (LONG)(sizeof(FORM) + sizeof(TYPE) +
  1129. X             sizeof(BMHD) + sizeof(BMHdr) +
  1130. X             sizeof(CAMG) + sizeof(ViewMode) +
  1131. X             sizeof(CMAP))) == -1L) {
  1132. X        return 0;
  1133. X    }
  1134. X    if (Write(SnapFile, (char *)&GS->rgb[0], CMAP.ChunkSize) == -1L) {
  1135. X        return 0;
  1136. X    }
  1137. X    BODYPos = Seek(SnapFile, 0L, OFFSET_CURRENT);
  1138. X    if (Write(SnapFile, (char *)&BODY, (LONG)sizeof(BODY)) == -1L) {
  1139. X        return 0;
  1140. X    }
  1141. X    if (!(BODY.ChunkSize = WriteBody(&GS->BM))) {
  1142. X        return 0;
  1143. X    }
  1144. X    FORM.ChunkSize = BODYPos - sizeof(FORM) + sizeof(BODY) + BODY.ChunkSize;
  1145. X    if (FORM.ChunkSize & 1) {                       /* Odd size */
  1146. X        if (Write(SnapFile, "X", 1L) == -1L) {
  1147. X            return 0;
  1148. X        }
  1149. X        ++FORM.ChunkSize;
  1150. X    }
  1151. X    Seek(SnapFile, 0L, OFFSET_BEGINNING);
  1152. X    Write(SnapFile, (char *)&FORM, (LONG)sizeof(FORM));
  1153. X    Seek(SnapFile, BODYPos, OFFSET_BEGINNING);
  1154. X    Write(SnapFile, (char *)&BODY, (LONG)sizeof(BODY));
  1155. X    SetWindowTitles(GS->window, oldtitle, NULL);
  1156. X    return 1;
  1157. X}
  1158. END_OF_FILE
  1159. if test 5748 -ne `wc -c <'source/saveilbm.c'`; then
  1160.     echo shar: \"'source/saveilbm.c'\" unpacked with wrong size!
  1161. fi
  1162. # end of 'source/saveilbm.c'
  1163. fi
  1164. if test -f 'source/snap.h' -a "${1}" != "-c" ; then 
  1165.   echo shar: Will not clobber existing file \"'source/snap.h'\"
  1166. else
  1167. echo shar: Extracting \"'source/snap.h'\" \(5276 characters\)
  1168. sed "s/^X//" >'source/snap.h' <<'END_OF_FILE'
  1169. X#include <intuition/intuitionbase.h>
  1170. X#ifdef AZTEC_C
  1171. X#include <functions.h>
  1172. Xstruct IORequest *CreateExtIO(); /* This is a kludge that is necessary    */
  1173. X                                 /* since this definition is missing from */
  1174. X                                 /* manx's <functions.h> include file.    */
  1175. X#endif AZTEC_C
  1176. X#include <libraries/arpbase.h>
  1177. X#include <devices/input.h>
  1178. X#include <devices/keymap.h>
  1179. X#include <devices/console.h>
  1180. X#include <devices/clipboard.h>
  1181. X#include <exec/memory.h>
  1182. X#include <exec/interrupts.h>
  1183. X#include <graphics/gfxmacros.h>
  1184. X
  1185. X#define Create(_Obj)     AllocMem((LONG)sizeof(struct _Obj), MEMF_PUBLIC|MEMF_CLEAR)
  1186. X#define Kill(_Obj)       FreeMem(_Obj, (LONG)sizeof(*_Obj))
  1187. X#define Delete(_Obj)     if (_Obj) FreeMem(_Obj, (LONG)sizeof(*_Obj))
  1188. X
  1189. X#define SNAPRSRC "Snap.resource"
  1190. X
  1191. Xstruct SnapRsrc {
  1192. X    struct Node node;
  1193. X    struct Task *Task;
  1194. X    WORD Priority;
  1195. X    WORD gfxqual;
  1196. X    WORD textqual;
  1197. X    WORD insertkey;
  1198. X    WORD cwkey;
  1199. X    char Prepend[17];
  1200. X    char Append[17];
  1201. X    WORD flags;
  1202. X    LONG chardelay;
  1203. X    LONG linedelay;
  1204. X    UWORD CrawlPtrn;
  1205. X    WORD StartUnit;
  1206. X    WORD FrameMask;
  1207. X    WORD GadOffset;
  1208. X    WORD CacheSize;
  1209. X    WORD BadChar;
  1210. X};
  1211. X
  1212. X#define XEROX           1
  1213. X#define EARLYPATCH      2
  1214. X#define TRUEUNDERSCORE  4
  1215. X#define JOINLONG        8
  1216. X
  1217. Xstruct Snap {
  1218. X    ULONG Size;
  1219. X    char Chars[1];
  1220. X};
  1221. X
  1222. Xstruct GfxSnap {
  1223. X    struct Gadget DiskGad;
  1224. X    struct Gadget VProp;
  1225. X    struct Gadget HProp;
  1226. X    struct PropInfo VInfo;
  1227. X    struct PropInfo HInfo;
  1228. X    struct Image VImage;
  1229. X    struct Image HImage;
  1230. X    LONG x, y;
  1231. X    LONG width, height;
  1232. X    LONG depth;
  1233. X    LONG viewmode;
  1234. X    char rgb[32][3];
  1235. X    SHORT pagew;
  1236. X    SHORT pageh;
  1237. X    struct Window *window;
  1238. X    struct BitMap BM;
  1239. X};
  1240. X
  1241. Xstruct CacheWindow {
  1242. X    struct MinNode Node;
  1243. X    struct Window *Window;
  1244. X    SHORT xoff;
  1245. X    SHORT yoff;
  1246. X    SHORT fw;
  1247. X    SHORT fh;
  1248. X};
  1249. X
  1250. X#define SAVEGAD 1
  1251. X#define DISKGAD 2
  1252. X#define NAMEGAD 3
  1253. X#define VPROP   4
  1254. X#define HPROP   5
  1255. X
  1256. X#define CLIP_FIRST 0
  1257. X#define CLIP_CONT  1
  1258. X#define CLIP_LAST  2
  1259. X
  1260. X#define TitleFont(win) ((struct TextFont *)(win->IFont ? win->IFont : win->RPort->Font))
  1261. X
  1262. X#define Swap2L(_x,_y) { REGISTER LONG _t = _x; _x = _y; _y = _t; }
  1263. X
  1264. X#define noaction 0
  1265. X#define snapgfx  1  /* window */
  1266. X#define snaptext 2  /* text */
  1267. X#define insert   4  /* inserting */
  1268. X
  1269. X#define waiting   0
  1270. X#define selregion 1
  1271. X#define waitext   2
  1272. X#define selgfx    3
  1273. X#define waitgfx   4
  1274. X
  1275. X#define UNIT_FRAME 1 /* rect of chars */
  1276. X#define UNIT_CHAR  2 /* characters with line wrap */
  1277. X#define UNIT_WORD  3 /* words with line wrap */
  1278. X#define UNIT_LINE  4 /* lines */
  1279. X
  1280. X#ifdef LATTICE
  1281. X#include <string.h>     /* Prototyping of string functions */
  1282. X#include <stdlib.h>     /* Prototyping of standard lib functions */
  1283. X#endif
  1284. X
  1285. X/* C_Args & ARGs borrowed from the Arp include file */
  1286. X
  1287. XULONG ReadClip ARGs( (struct IOClipReq *, STRPTR, ULONG, WORD) );
  1288. XVOID WriteClip ARGs( (struct IOClipReq *, STRPTR, ULONG, WORD) );
  1289. XVOID SaveClip ARGs( (UBYTE *, ULONG) );
  1290. Xstruct Snap *FetchClip ARGs( (VOID) );
  1291. XVOID MultiDraw ARGs( (struct RastPort *, LONG, Point *) );
  1292. XVOID crawl_frame ARGs( (LONG) );
  1293. XVOID erase_frame ARGs( (VOID) );
  1294. XVOID draw_frame ARGs( (LONG) );
  1295. XULONG InvertKeyMap ARGs( (ULONG, struct InputEvent *, struct KeyMap *) );
  1296. XUWORD LowKeyInvert ARGs( (register UBYTE, struct KeyMap *, UWORD *, UWORD *, ULONG *) );
  1297. XVOID IndexKey ARGs( (ULONG, struct KeyMap *, ULONG *) );
  1298. XWORD checkNormal ARGs( (LONG, UBYTE, UWORD, UWORD *) );
  1299. XWORD checkVanilla ARGs( (UBYTE *, UBYTE, UWORD *) );
  1300. XWORD checkDead ARGs( (UBYTE **, UBYTE, UWORD *, ULONG *) );
  1301. XWORD deadQual ARGs( (WORD, UWORD *) );
  1302. Xstruct Screen *WhichScreen ARGs( (VOID) );
  1303. Xstruct Window *WhichWindow ARGs( (struct Screen *) );
  1304. XVOID FreePlanes ARGs( (struct BitMap *, LONG, LONG) );
  1305. XWORD AllocPlanes ARGs( (struct BitMap *, LONG, LONG) );
  1306. XVOID CacheWindow ARGs( (struct Window *, LONG, LONG, SHORT, SHORT) );
  1307. Xstruct CacheWindow *GetCachedWindow ARGs( (struct Screen *, struct Window *) );
  1308. XVOID CloseStuff ARGs( (VOID) );
  1309. XWORD OpenStuff ARGs( (VOID) );
  1310. XVOID SafePatch ARGs( (VOID) );
  1311. XVOID SafeRestore ARGs( (VOID) );
  1312. XWORD bump ARGs( (WORD, UBYTE *, WORD) );
  1313. XULONG WriteBody ARGs( (struct BitMap *) );
  1314. XWORD SaveGS ARGs( (struct GfxSnap *) );
  1315. XWORD isdigit ARGs( (char) );
  1316. XLONG dectoint ARGs( (char *) );
  1317. XLONG hextoint ARGs( (char *) );
  1318. XVOID InsertAscii ARGs( (ULONG) );
  1319. XVOID GadText ARGs( (struct Gadget *, char *, LONG) );
  1320. XVOID SwapColorMap ARGs( (struct GfxSnap *) );
  1321. XVOID CheckWindowMsgs ARGs( (VOID) );
  1322. XVOID SetSnapFont ARGs( (struct TextFont *) );
  1323. XWORD IsSpace ARGs( (LONG, LONG) );
  1324. XVOID update_frame ARGs( (VOID) );
  1325. XVOID FindWord ARGs( (VOID) );
  1326. XVOID ChangeUnit ARGs( (VOID) );
  1327. XVOID ExtendSelection ARGs( (VOID) );
  1328. XWORD SnapChars ARGs( (VOID) );
  1329. XWORD HandleChars ARGs( (VOID) );
  1330. XVOID FixHeights ARGs( (VOID) );
  1331. Xstruct GfxSnap *SnapGfx ARGs( (struct RastPort *) );
  1332. XVOID ExtendGfx ARGs( (VOID) );
  1333. XVOID gfx_frame ARGs( (VOID) );
  1334. XWORD HandleGfx ARGs( (VOID) );
  1335. Xstruct Window *opensharedwindow ARGs( (struct NewWindow *) );
  1336. XVOID closesharedwindow ARGs( (struct Window *) );
  1337. XVOID SetUpBorder ARGs( (struct Border *, struct Gadget *) );
  1338. XVOID AdjustSize ARGs( (struct GfxSnap *) );
  1339. XVOID SyncGS ARGs( (struct GfxSnap *) );
  1340. XSHORT OpenCW ARGs( (VOID) );
  1341. XUBYTE C_Args interpret ARGs( (UWORD *) );
  1342. XVOID CopyFont ARGs( (VOID) );
  1343. XVOID myhandler();
  1344. END_OF_FILE
  1345. if test 5276 -ne `wc -c <'source/snap.h'`; then
  1346.     echo shar: \"'source/snap.h'\" unpacked with wrong size!
  1347. fi
  1348. # end of 'source/snap.h'
  1349. fi
  1350. if test -f 'source/snapasm.s' -a "${1}" != "-c" ; then 
  1351.   echo shar: Will not clobber existing file \"'source/snapasm.s'\"
  1352. else
  1353. echo shar: Extracting \"'source/snapasm.s'\" \(8453 characters\)
  1354. sed "s/^X//" >'source/snapasm.s' <<'END_OF_FILE'
  1355. X        XDEF    _interpret       ; Bitmap-to-Ascii function
  1356. X        XDEF    _CopyFont        ; Copies a font and aligns it to 16 bit.
  1357. X        XREF    _CharData        ; Font data
  1358. X        XREF    _SrcData
  1359. X        XREF    _CharLoc
  1360. X        XREF    _Modulo
  1361. X        XREF    _FontWidth
  1362. X        XREF    _FontHeight
  1363. X        XREF    _Underscore
  1364. X        XREF    _TrueUnderscore
  1365. X        XREF    _LoChar
  1366. X        XREF    _HiChar
  1367. X        XREF    _IFlags
  1368. X
  1369. X        XDEF   _myActivateWindow
  1370. X        XDEF   _myWindowToFront
  1371. X        XDEF   _myWindowToBack
  1372. X
  1373. X        SECTION CODE
  1374. X
  1375. XUSC     equ 1                   ; Interpreted char was underscored
  1376. XPUSC    equ 2                   ; Prevoius char was underscored
  1377. XPUS     equ 4                   ; Pending underscored space
  1378. X
  1379. X_interpret:
  1380. X        link    a5,#0
  1381. X        movem.l d1-d6/a1,-(sp)   ; Free a couple of registers
  1382. X        move.l  8(a5),a1         ; Bitmap
  1383. X        move.w  (a1),d2          ; First row
  1384. X        moveq   #0,d4            ; Code
  1385. X        move.b  _LoChar,d4       ; First char
  1386. X        move.w  _FontWidth,d0
  1387. X        asl.w   #1,d0            ; Times two for words
  1388. X        lea     MaskTable,a0
  1389. X        move.w  0(a0,d0.w),d3    ; d3 := mask
  1390. X        move.l  _CharData,a0     ; Char image data
  1391. X        bclr.b  #PUS,_IFlags     ; No pending-underscored-space
  1392. X.lp1
  1393. X        cmpi.b  #31,d4           ; Into printable characters yet?
  1394. X        bhi     .Search          ; If yes, go and start searching
  1395. X        addq    #1,d4            ; Move to next char
  1396. X        adda.l  #32,a0           ; Increment bitmap ptr also
  1397. X        bra     .lp1             ; Back to check again
  1398. X.Search
  1399. X        cmp.w   (a0),d2          ; Compare first word
  1400. X        bne     .tryinverted     ; Not this one
  1401. X        bclr.b  #USC,_IFlags     ; Assume not underscored
  1402. X        moveq   #1,d5            ; current word
  1403. X        moveq   #0,d6            ; Modulo
  1404. X.morerows
  1405. X        addq    #2,d6            ; Add modulo - next bit row in image data
  1406. X        move.w  0(a0,d6.w),d1    ; Character row
  1407. X        cmp.w   0(a1,d6.w),d1
  1408. X        beq     .stdmatch        ; Rows matched
  1409. X        cmp.w   _Underscore,d5   ; Could it be the underscore line?
  1410. X        bne     .tryinverted     ; Nope
  1411. X        tst.b   _TrueUnderscore  ; Use true underscore?
  1412. X        beq     .uscmatch        ; No. Let's hope it's okay
  1413. X        moveq   #0,d1            ;   00000000
  1414. X        move.w  0(a0,d6.w),d0    ;   00110000
  1415. X        or.w    d0,d1            ;   00110000
  1416. X        rol.l   #2,d1            ; 0011000000
  1417. X        or.w    d0,d1            ; 0011110000
  1418. X        ror.l   #1,d1            ;  X01111000
  1419. X        eor.w   d3,d1            ;   10000111
  1420. X        or.w    d0,d1            ;   10110111
  1421. X        move.w  0(a1,d6.w),d0
  1422. X        eor.w   d0,d1            ;   Zero if equal
  1423. X                                 ; But, let's skip the last bit since it
  1424. X                                 ; may be affected by the next character
  1425. X        lsr.w   #1,d1            ; Shift one step right
  1426. X        and.w   d3,d1            ; Mask out last bit
  1427. X        bne     .tryinverted
  1428. X.uscmatch
  1429. X        bset.b  #USC,_IFlags     ; Set underscored flag
  1430. X.stdmatch
  1431. X        addq    #1,d5            ; Next row in bitmap
  1432. X        cmp.w   _FontHeight,d5   ; Are we done?
  1433. X        bne     .morerows        ; Not yet
  1434. X        cmp.b   #32,d4           ; Space
  1435. X        bne     .notuspace
  1436. X        ; Space. Check for underscore
  1437. X        btst.b  #USC,_IFlags     ; Underscored char?
  1438. X        beq     .notuspace       ; Nope, everything ok
  1439. X        ; Underscored space. Check if previous char was underscored
  1440. X        btst.b  #PUSC,_IFlags    ; Previous char underscored?
  1441. X        bne     .okuspace        ; Yep, ok underscored space
  1442. X        ; Previous char not underscored. Set pending-underscored-space flag
  1443. X        ; and go on to check if the normal underscore char matches
  1444. X        bset.b  #PUS,_IFlags
  1445. X        bra     .tryinverted
  1446. X
  1447. X.notuspace
  1448. X.okuspace
  1449. X        bclr.b  #PUSC,_IFlags    ; Clear previous-underscored
  1450. X        btst.b  #USC,_IFlags     ; Underscored char?
  1451. X        beq     .interpreted     ; Nope
  1452. X        bset.b  #PUSC,_IFlags    ; Set previous-underscored
  1453. X        bra     .interpreted     ; Got it
  1454. X
  1455. X.tryinverted
  1456. X        move.w  (a0),d1          ; Copy first row
  1457. X        eor.w   d3,d1            ; and invert the bits
  1458. X        cmp.w   d2,d1            ; Compare inverted rows
  1459. X        bne     .trybold         ; No match
  1460. X        moveq   #1,d5            ; current row
  1461. X        moveq   #0,d6            ; Modulo
  1462. X.moreinverted
  1463. X        addq    #2,d6
  1464. X        move.w  0(a0,d6.w),d1    ; Character row
  1465. X        eor.w   d3,d1            ; and invert the bits
  1466. X        cmp.w   0(a1,d6.w),d1
  1467. X        bne     .trybold         ; Rows didn't match
  1468. X        addq    #1,d5            ; Next row in bitmap
  1469. X        cmp.w   _FontHeight,d5   ; Are we done?
  1470. X        bne     .moreinverted    ; Not yet
  1471. X        bra     .interpreted     ; Got it
  1472. X
  1473. X.trybold
  1474. X        move.w  (a0),d1          ; Copy first row
  1475. X        lsr.w   #1,d1            ; Shift one step left
  1476. X        or.w    (a0),d1          ; Make bold
  1477. X        and.w   d3,d1            ; and mask out unwanted bits
  1478. X        cmp.w   d2,d1            ; Compare bold rows
  1479. X        bne     .trynext         ; No match
  1480. X        moveq   #1,d5            ; current row
  1481. X        moveq   #0,d6            ; Modulo
  1482. X.morebold
  1483. X        addq    #2,d6
  1484. X        move.w  0(a0,d6.w),d1    ; Character row
  1485. X        lsr.w   #1,d1            ; Shift one step left
  1486. X        or.w    0(a0,d6.w),d1    ; Make bold
  1487. X        and.w   d3,d1            ; and mask out unwanted bits
  1488. X        cmp.w   0(a1,d6.w),d1
  1489. X        bne     .trynext         ; Rows didn't match
  1490. X        addq    #1,d5            ; Next row in bitmap
  1491. X        cmp.w   _FontHeight,d5   ; Are we done?
  1492. X        bne     .morebold        ; Not yet
  1493. X        bra     .interpreted     ; Got it
  1494. X
  1495. X.trynext
  1496. X        adda.l  #32,a0           ; Try next character, 32 bytes/char
  1497. X        addq    #1,d4            ;
  1498. X        cmp.b   _HiChar,d4       ; Tried all chars?
  1499. X        bne     .Search          ; More to try
  1500. X        move.l  #255,d4          ; Not found
  1501. X        btst.b  #PUS,_IFlags     ; Hey, perhaps it was an underscored space?
  1502. X        beq     .interpreted     ; Nope, return not-found
  1503. X        move.l  #32,d4
  1504. X
  1505. X.interpreted
  1506. X        move.l  d4,d0
  1507. X        movem.l (sp)+,d1-d6/a1
  1508. X        unlk    a5
  1509. X        rts
  1510. X
  1511. X
  1512. X_CopyFont:
  1513. X        movem.l d2-d5/a2-a3,-(sp)   ; Free a couple of registers
  1514. X        moveq   #0,d0
  1515. X        move.l  _CharData,a2        ; a2 := Destination area
  1516. X        move.l  _CharLoc,a3
  1517. X        move.b  _LoChar,d5
  1518. X        move.w  _Modulo,d3
  1519. X
  1520. X.NextChar
  1521. X        move.w  (a3),d0             ; Get char location
  1522. X        adda.w  #4,a3               ; To next, and skip width
  1523. X        move.w  d0,d1
  1524. X        and.w   #15,d1              ; Shift amount
  1525. X        eori.b  #15,d1              ; Negate shift value
  1526. X        addq.b  #1,d1               ; d1 := Shift Amount
  1527. X
  1528. X        move.l  _SrcData,a0
  1529. X        lsr.w   #3,d0               ; Byte offset
  1530. X        bclr    #0,d0               ; But we deal in words
  1531. X        adda.w  d0,a0               ; a0 := chardata
  1532. X
  1533. X        move.w  _FontWidth,d0
  1534. X        asl.w   #1,d0               ; Times two for words
  1535. X        lea     MaskTable,a1
  1536. X        move.w  0(a1,d0.w),d2       ; d2 := mask
  1537. X
  1538. X        moveq   #0,d4
  1539. X        move.w  _FontHeight,d4
  1540. X        move.l  a2,a1               ; a1 := Destination area
  1541. X        adda.w  #32,a2              ; a2 to next dest area
  1542. X        bra     .loop
  1543. X.copyrow
  1544. X        move.l  (a0),d0             ; Get character row
  1545. X        adda.w  d3,a0               ; Add modulo -- To next row
  1546. X        lsr.l   d1,d0               ; Shift data to bit 0 alignment
  1547. X        and.w   d2,d0               ; Mask out unwanted bits
  1548. X        move.w  d0,(a1)+            ; Save row
  1549. X.loop
  1550. X        dbra    d4,.copyrow         ; Do all rows
  1551. X
  1552. X        addq    #1,d5               ; Next char
  1553. X        cmp.b   _HiChar,d5          ; Finished?
  1554. X        bne     .NextChar           ; Nope -- do next.
  1555. X        movem.l (sp)+,d2-d5/a2-a3
  1556. X        rts
  1557. X
  1558. XMaskTable
  1559. X        dc.w    $0000
  1560. X        dc.w    $8000
  1561. X        dc.w    $c000
  1562. X        dc.w    $e000
  1563. X        dc.w    $f000
  1564. X        dc.w    $f800
  1565. X        dc.w    $fc00
  1566. X        dc.w    $fe00
  1567. X        dc.w    $ff00
  1568. X        dc.w    $ff80
  1569. X        dc.w    $ffc0
  1570. X        dc.w    $ffe0
  1571. X        dc.w    $fff0
  1572. X        dc.w    $fff8
  1573. X        dc.w    $fffc
  1574. X        dc.w    $fffe
  1575. X        dc.w    $ffff
  1576. X
  1577. X
  1578. X_myActivateWindow:
  1579. X        rts
  1580. X
  1581. X_myWindowToFront:
  1582. X        rts
  1583. X
  1584. X_myWindowToBack:
  1585. X        rts
  1586. X
  1587. X        END
  1588. END_OF_FILE
  1589. if test 8453 -ne `wc -c <'source/snapasm.s'`; then
  1590.     echo shar: \"'source/snapasm.s'\" unpacked with wrong size!
  1591. fi
  1592. # end of 'source/snapasm.s'
  1593. fi
  1594. if test -f 'source/snapgfx.c' -a "${1}" != "-c" ; then 
  1595.   echo shar: Will not clobber existing file \"'source/snapgfx.c'\"
  1596. else
  1597. echo shar: Extracting \"'source/snapgfx.c'\" \(8157 characters\)
  1598. sed "s/^X//" >'source/snapgfx.c' <<'END_OF_FILE'
  1599. X/* Auto: make
  1600. X*/
  1601. X
  1602. XIMPORT struct SnapRsrc *SnapRsrc;
  1603. XIMPORT struct Image DiskImage;
  1604. XIMPORT struct Gadget DiskGad;
  1605. XIMPORT struct Gadget VProp, HProp;
  1606. XIMPORT struct PropInfo VInfo, HInfo;
  1607. XIMPORT struct Image VImage, HImage;
  1608. XIMPORT struct NewWindow Nw;
  1609. XIMPORT UBYTE *WindowTitle;
  1610. X
  1611. X#define MINWIDTH (24 + SnapRsrc->GadOffset + 16)
  1612. X#define MINHEIGHT 15
  1613. X
  1614. XLONG xl; /* leftmost x position */
  1615. XLONG xr; /* rightmost x position */
  1616. XLONG yt; /* topmost y position */
  1617. XLONG yb; /* bottommost y position */
  1618. XLONG mx, my; /* Mouse position in pixels */
  1619. X
  1620. X#define GfxFrame 4L
  1621. XIMPORT Point OldFrame[];
  1622. XIMPORT Point NewFrame[];
  1623. XIMPORT LONG OFType;        /* Old frame type: ShortFrame/LongFrame */
  1624. XIMPORT UWORD Ptrn;
  1625. XIMPORT WORD Pattern[];
  1626. X
  1627. XIMPORT struct RastPort MyRP;
  1628. XIMPORT struct BitMap MyBM;
  1629. XIMPORT struct Screen *theScreen;
  1630. Xstruct Layer_Info *LockedLayerInfo;
  1631. XIMPORT struct RastPort rp;
  1632. X
  1633. XIMPORT LONGBITS cancelsignal, donesignal, movesignal, clicksignal, timersignal;
  1634. XIMPORT WORD action;
  1635. X
  1636. XLONG TitleBarHeight;
  1637. XLONG ContentsFontHeight;
  1638. X
  1639. XVOID FixHeights()
  1640. X{
  1641. X    struct Screen WBScreen;
  1642. X    if (GetScreenData((char *)&WBScreen, (LONG)sizeof(struct Screen), WBENCHSCREEN, NULL)) {
  1643. X          /* Now this is a good practice */
  1644. X        TitleBarHeight = WBScreen.RastPort.TxHeight+2;
  1645. X        ContentsFontHeight = WBScreen.Font->ta_YSize;
  1646. X    } else {
  1647. X          /* Sorry, but I don't realise how this could fail.
  1648. X             Well, if we're snapping on another screen and
  1649. X             WB is closed and it can't be opened by GetScreenData()...
  1650. X             Anyway, IF this should happen -- Use Topaz 8 */
  1651. X        TitleBarHeight = 10;
  1652. X        ContentsFontHeight = 8;
  1653. X    }
  1654. X}
  1655. X
  1656. X/* SnapGfx is the actual graphics snapper.
  1657. X** It steals the bitmap data from the given rastport
  1658. X** and puts it in a separate bitmap.
  1659. X** It also prepares the NewWindow structure according
  1660. X** to the snapped bitmap.
  1661. X** The coordinates are assumed to be valid.
  1662. X*/
  1663. X
  1664. Xstruct GfxSnap *SnapGfx(rp)
  1665. Xstruct RastPort *rp;
  1666. X{
  1667. X    struct GfxSnap *GS;
  1668. X    LONG i;
  1669. X
  1670. X    GS = Create(GfxSnap);
  1671. X    if (!GS) {
  1672. X        return NULL;
  1673. X    }
  1674. X
  1675. X    GS->x = xl;
  1676. X    GS->y = yt;
  1677. X    GS->width = xr - xl + 1;
  1678. X    GS->height = yb - yt + 1;
  1679. X    GS->depth = rp->BitMap->Depth;
  1680. X    GS->viewmode = theScreen->ViewPort.Modes;
  1681. X    GS->pagew = theScreen->Width;
  1682. X    GS->pageh = theScreen->Height;
  1683. X    i = (GS->viewmode & HAM ? 16 : 1L << GS->depth);
  1684. X      /* Copy the color map in case we should need it later */
  1685. X    while (i--) {
  1686. X        ULONG col = GetRGB4(theScreen->ViewPort.ColorMap, i);
  1687. X        GS->rgb[i][0] = ((col >> 8) & 0x0f) << 4;
  1688. X        GS->rgb[i][1] = ((col >> 4) & 0x0f) << 4;
  1689. X        GS->rgb[i][2] = ((col >> 0) & 0x0f) << 4;
  1690. X    }
  1691. X      /* Set up a nice bitmap */
  1692. X    InitBitMap(&GS->BM, GS->depth, GS->width, GS->height);
  1693. X      /* Get a handle on the bitmap */
  1694. X    InitRastPort(&MyRP);
  1695. X    MyRP.BitMap = &GS->BM;
  1696. X    if (!AllocPlanes(&GS->BM, GS->width, GS->height)) {
  1697. X        FreePlanes(&GS->BM, GS->width, GS->height);
  1698. X        Kill(GS);
  1699. X        return NULL;
  1700. X    }
  1701. X      /* Copy the selected part of the screen */
  1702. X    ClipBlit(rp, xl, yt, &MyRP, 0L, 0L, GS->width, GS->height, 0xC0L);
  1703. X    Nw.LeftEdge = xl;
  1704. X    Nw.TopEdge = yt;
  1705. X    Nw.Width = GS->width + 18;                   /* Two pixels on each side */
  1706. X    Nw.Height = GS->height + TitleBarHeight + 9; /* Bar & scroll bar */
  1707. X    Nw.Title = WindowTitle;
  1708. X    Nw.MaxWidth = Nw.Width;
  1709. X    Nw.MaxHeight = Nw.Height;
  1710. X    CopyMem((char *)&DiskGad, (char *)&GS->DiskGad,
  1711. X      (LONG)sizeof(DiskGad) + sizeof(VProp) + sizeof(HProp) +
  1712. X      sizeof(VInfo) + sizeof(HInfo) + sizeof(VImage) + sizeof(HImage));
  1713. X    GS->DiskGad.NextGadget = &GS->VProp;
  1714. X    GS->DiskGad.LeftEdge = -(SnapRsrc->GadOffset+16);
  1715. X    GS->DiskGad.Height = TitleBarHeight - 2;
  1716. X    DiskImage.Height = TitleBarHeight;
  1717. X    GS->VProp.NextGadget = &GS->HProp;
  1718. X    GS->VProp.TopEdge = TitleBarHeight;
  1719. X    GS->VProp.Height = -8 - TitleBarHeight;
  1720. X    GS->VProp.GadgetRender = (APTR)&GS->VImage;
  1721. X    GS->VProp.SpecialInfo = (APTR)&GS->VInfo;
  1722. X    GS->HProp.NextGadget = NULL;
  1723. X    GS->HProp.GadgetRender = (APTR)&GS->HImage;
  1724. X    GS->HProp.SpecialInfo = (APTR)&GS->HInfo;
  1725. X    return GS;
  1726. X}
  1727. X
  1728. XVOID ExtendGfx()
  1729. X{
  1730. X    /* Fix which row we're talking about */
  1731. X    if (my-yt < yb-my) {       /* Find closest row */
  1732. X        yt = my;               /* change top row */
  1733. X    } else {
  1734. X        yb = my;               /* change bottom row */
  1735. X    }
  1736. X    if (mx-xl < xr-mx) {
  1737. X        xl = mx;
  1738. X    } else {
  1739. X        xr = mx;
  1740. X    }
  1741. X}
  1742. X
  1743. XVOID gfx_frame()
  1744. X{
  1745. X    NewFrame[0].x = xl;  NewFrame[0].y = yt;
  1746. X    NewFrame[1].x = xr;  NewFrame[1].y = yt;
  1747. X    NewFrame[2].x = xr;  NewFrame[2].y = yb;
  1748. X    NewFrame[3].x = xl;  NewFrame[3].y = yb;
  1749. X    NewFrame[4].x = xl;  NewFrame[4].y = yt;
  1750. X    draw_frame(GfxFrame);
  1751. X}
  1752. X
  1753. XWORD HandleGfx()
  1754. X{
  1755. X    theScreen = WhichScreen();   /* Find out where we are */
  1756. X    if (!theScreen) {            /* Don't know? Forget it. */
  1757. X        action = noaction;
  1758. X        return 0;
  1759. X    }
  1760. X      /* Lock everything - find out what happens */
  1761. X    LockedLayerInfo = &theScreen->LayerInfo;
  1762. X    LockLayers(LockedLayerInfo);
  1763. X
  1764. X      /* Get a copy. Don't mess with somebody else's RP. */
  1765. X    CopyMem((char *)&theScreen->RastPort, (char *)&rp, (long)sizeof(struct RastPort));
  1766. X    SetDrMd(&rp, COMPLEMENT);
  1767. X
  1768. X    xl = theScreen->MouseX + theScreen->ViewPort.RasInfo->RxOffset;
  1769. X    if (xl < 0) {
  1770. X        xl = 0;
  1771. X    }
  1772. X    if (xl >= theScreen->Width) {  /* Check those corners. Check those corners. */
  1773. X        xl = theScreen->Width - 1;
  1774. X    }
  1775. X    yt = theScreen->MouseY + theScreen->ViewPort.RasInfo->RyOffset;
  1776. X    if (yt < 0) {
  1777. X        yt = 0;
  1778. X    }
  1779. X    if (yt >= theScreen->Height) {
  1780. X        yt = theScreen->Height - 1;
  1781. X    }
  1782. X    xr = xl;
  1783. X    yb = yt;
  1784. X    Ptrn = (SnapRsrc->CrawlPtrn ? SnapRsrc->CrawlPtrn : Pattern[UNIT_FRAME]);
  1785. X    OFType = 0L;
  1786. X    gfx_frame();
  1787. X
  1788. X    FOREVER {
  1789. X        REGISTER LONGBITS sig =
  1790. X          Wait(movesignal|clicksignal|cancelsignal|donesignal|timersignal);
  1791. X
  1792. X        if ((sig & timersignal) && (SnapRsrc->CrawlPtrn != 0xffff)) {
  1793. X            crawl_frame(1L);
  1794. X        }
  1795. X
  1796. X        if (sig & movesignal || sig & clicksignal) {
  1797. X            mx = theScreen->MouseX + theScreen->ViewPort.RasInfo->RxOffset;
  1798. X            if (mx < 0) {
  1799. X                mx = 0;
  1800. X            }
  1801. X            if (mx>=theScreen->Width) {
  1802. X                mx = theScreen->Width - 1;
  1803. X            }
  1804. X            my = theScreen->MouseY + theScreen->ViewPort.RasInfo->RyOffset;
  1805. X            if (my < 0) {
  1806. X                my = 0;
  1807. X            }
  1808. X            if (my>=theScreen->Height) {
  1809. X                my = theScreen->Height - 1;
  1810. X            }
  1811. X            ExtendGfx();
  1812. X            gfx_frame();
  1813. X        }
  1814. X        if (sig & cancelsignal) {          /* Cancelled? */
  1815. X            erase_frame();
  1816. X            UnlockLayers(LockedLayerInfo);
  1817. X            return 0;
  1818. X        }
  1819. X        if (sig & donesignal) {            /* Finished. Copy gfx. */
  1820. X            struct GfxSnap *GS;
  1821. X
  1822. X            erase_frame();
  1823. X            if (xr < xl + MINWIDTH) {          /* Can't have too small windows */
  1824. X                xr = xl + MINWIDTH;
  1825. X            }
  1826. X            if (xr >= theScreen->Width) {
  1827. X                xl -= xr - theScreen->Width - 1;
  1828. X                xr = theScreen->Width - 1;
  1829. X            }
  1830. X            if (yb < yt + MINHEIGHT) {
  1831. X                yb = yt + MINHEIGHT;
  1832. X            }
  1833. X            if (yb >= theScreen->Height) {
  1834. X                yt -= yb - theScreen->Height - 1;
  1835. X                yb = theScreen->Height - 1;
  1836. X            }
  1837. X            FixHeights();
  1838. X            GS = SnapGfx(&rp); /* Snap! */
  1839. X            UnlockLayers(LockedLayerInfo);
  1840. X            if (GS) {
  1841. X                if (GS->window = opensharedwindow(&Nw)) {
  1842. X                    GS->window->UserData = (BYTE *)GS;
  1843. X                      /* Put gfx in our new window */
  1844. X                    (VOID)AddGList(GS->window, &GS->DiskGad, 0L, 3L, NULL);
  1845. X                    RefreshGList(&GS->DiskGad, GS->window, NULL, 3L);
  1846. X                    AdjustSize(GS);
  1847. X                } else {
  1848. X                    FreePlanes(&GS->BM, GS->width, GS->height);
  1849. X                    Kill(GS);
  1850. X                }
  1851. X            } else { /* Good question */
  1852. X            }
  1853. X            action = noaction;
  1854. X            return 0;
  1855. X        }
  1856. X    }
  1857. X}
  1858. END_OF_FILE
  1859. if test 8157 -ne `wc -c <'source/snapgfx.c'`; then
  1860.     echo shar: \"'source/snapgfx.c'\" unpacked with wrong size!
  1861. fi
  1862. # end of 'source/snapgfx.c'
  1863. fi
  1864. echo shar: End of archive 1 \(of 4\).
  1865. cp /dev/null ark1isdone
  1866. MISSING=""
  1867. for I in 1 2 3 4 ; do
  1868.     if test ! -f ark${I}isdone ; then
  1869.     MISSING="${MISSING} ${I}"
  1870.     fi
  1871. done
  1872. if test "${MISSING}" = "" ; then
  1873.     echo You have unpacked all 4 archives.
  1874.     rm -f ark[1-9]isdone
  1875. else
  1876.     echo You still need to unpack the following archives:
  1877.     echo "        " ${MISSING}
  1878. fi
  1879. ##  End of shell archive.
  1880. exit 0
  1881. -- 
  1882. Mail submissions (sources or binaries) to <amiga@cs.odu.edu>.
  1883. Mail comments to the moderator at <amiga-request@cs.odu.edu>.
  1884. Post requests for sources, and general dicussion to comp.sys.amiga.
  1885.